package com.xbongbong.pay.platform.alipay.utils;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayRequest;
import com.alipay.api.AlipayResponse;
import com.alipay.api.BatchAlipayRequest;
import com.alipay.api.BatchAlipayResponse;
import com.xbongbong.pay.platform.alipay.config.AliPayMeta;

public class AliPayClient {


    public static <T extends AlipayResponse> T doExecute(AlipayRequest<T> request, AliPayMeta aliPayMeta) throws AlipayApiException {
        if (aliPayMeta.isCertModel()) {
            return certificateExecute(request, aliPayMeta);
        } else {
            return execute(request, aliPayMeta);
        }
    }

    public static <T extends AlipayResponse> T doExecute(AlipayRequest<T> request, String authToken, AliPayMeta aliPayMeta) throws AlipayApiException {
        if (aliPayMeta.isCertModel()) {
            return certificateExecute(request, authToken, aliPayMeta);
        } else {
            return execute(request, authToken, aliPayMeta);
        }
    }

    public static <T extends AlipayResponse> T execute(AlipayRequest<T> request, AliPayMeta aliPayMeta) throws AlipayApiException {
        return aliPayMeta.getAlipayClient().execute(request);
    }

    public static <T extends AlipayResponse> T execute(AlipayRequest<T> request, String authToken, AliPayMeta aliPayMeta) throws AlipayApiException {
        return aliPayMeta.getAlipayClient().execute(request, authToken);
    }

    public static <T extends AlipayResponse> T execute(AlipayRequest<T> request, String accessToken, String appAuthToken, AliPayMeta aliPayMeta) throws AlipayApiException {
        return aliPayMeta.getAlipayClient().execute(request, accessToken, appAuthToken);
    }

    public static <T extends AlipayResponse> T execute(AlipayRequest<T> request, String accessToken, String appAuthToken, String targetAppId, AliPayMeta aliPayMeta) throws AlipayApiException {
        return aliPayMeta.getAlipayClient().execute(request, accessToken, appAuthToken, targetAppId);
    }

    public static <T extends AlipayResponse> T pageExecute(AlipayRequest<T> request, AliPayMeta aliPayMeta) throws AlipayApiException {
        return aliPayMeta.getAlipayClient().pageExecute(request);
    }

    public static <T extends AlipayResponse> T pageExecute(AlipayRequest<T> request, String method, AliPayMeta aliPayMeta) throws AlipayApiException {
        return aliPayMeta.getAlipayClient().pageExecute(request, method);
    }

    public static <T extends AlipayResponse> T sdkExecute(AlipayRequest<T> request, AliPayMeta aliPayMeta) throws AlipayApiException {
        return aliPayMeta.getAlipayClient().sdkExecute(request);
    }

    public static BatchAlipayResponse execute(BatchAlipayRequest request, AliPayMeta aliPayMeta) throws AlipayApiException {
        return aliPayMeta.getAlipayClient().execute(request);
    }

    public static <T extends AlipayResponse> T certificateExecute(AlipayRequest<T> request, AliPayMeta aliPayMeta) throws AlipayApiException {
        return aliPayMeta.getAlipayClient().certificateExecute(request);
    }

    public static <T extends AlipayResponse> T certificateExecute(AlipayRequest<T> request, String authToken, AliPayMeta aliPayMeta) throws AlipayApiException {
        return aliPayMeta.getAlipayClient().certificateExecute(request, authToken);
    }

    public static <T extends AlipayResponse> T certificateExecute(AlipayRequest<T> request, String accessToken, String appAuthToken, AliPayMeta aliPayMeta) throws AlipayApiException {
        return aliPayMeta.getAlipayClient().certificateExecute(request, accessToken, appAuthToken);
    }

    public static <T extends AlipayResponse> T certificateExecute(AlipayRequest<T> request, String accessToken, String appAuthToken, String targetAppId, AliPayMeta aliPayMeta) throws AlipayApiException {
        return aliPayMeta.getAlipayClient().certificateExecute(request, accessToken, appAuthToken, targetAppId);
    }
}
